home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: ColoredCheckBox */
- /* */
- /* Description: This app demonstrates how to create a check box on the */
- /* gray window backgrounds.The key to this is making sure */
- /* that the background color for the window is set. */
- /* a 'wctb' was created using ResEdit which provides the */
- /* gray content for the window. I also Derezed the app and */
- /* made a coloredCheckBox.r file just to show you what's */
- /* going on in the 'wctb' structure. */
- /* */
- /* Files: ColoredCheckBox.π */
- /* main.c */
- /* ColoredCheckBox.π.RSRC */
- /* */
- /* Programmer: Larry Lai */
- /* Organization: Apple Computer, Inc. */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 7.0) */
- /* Date Created: 09-02-94 */
- /* */
- /****************************************************************************/
-
- #include <Sound.h>
-
- #define rColoredCheckBoxWindow 128
- #define rCheckBox 128
- #define kSoundID 128
-
- Boolean gQuit;
-
- void InitToolbox(void);
- void MyCreateColoredCheckBoxWindow();
- void DoEventLoop();
- void DoContentClick(WindowPtr, EventRecord);
- void DoCheckBox(Point, ControlHandle);
-
- void InitToolbox()
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- InitDialogs(0L);
- InitCursor();
- }
-
- main()
- {
-
- InitToolbox();
-
- MyCreateColoredCheckBoxWindow();
-
- DoEventLoop();
- }
-
- void MyCreateColoredCheckBoxWindow()
- {
- WindowPtr myWindow;
- ControlHandle gMyColoredCheckBoxWindow;
-
- myWindow = GetNewCWindow(rColoredCheckBoxWindow, nil, (WindowPtr) -1);
- if (myWindow != nil)
- {
- SetPort (myWindow);
- GetNewControl(rCheckBox, myWindow);
- }
- else
- SysBeep(10);
-
- }
-
- void DoEventLoop()
- {
- EventRecord anEvent;
- WindowPtr evtWind;
- short clickArea;
- Rect screenRect;
-
- do{
- if (WaitNextEvent( everyEvent, &anEvent, 0, nil ))
- {
- if (anEvent.what == mouseDown)
- {
- clickArea = FindWindow( anEvent.where, &evtWind );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn ()).rgnBBox;
- DragWindow( evtWind, anEvent.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (evtWind != FrontWindow())
- SelectWindow( evtWind );
- else
- DoContentClick(evtWind, anEvent);
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( evtWind, anEvent.where ))
- gQuit = true;
- }
- else if (anEvent.what == updateEvt)
- {
- evtWind = (WindowPtr)anEvent.message;
- SetPort( evtWind );
-
- BeginUpdate( evtWind );
- UpdateControls(evtWind, evtWind->visRgn);
- EndUpdate (evtWind);
- }
- }
- }while (!gQuit);
- }
-
-
- void DoContentClick(WindowPtr theWindow, EventRecord theEvent)
- {
- Point mouse;
- ControlHandle control;
- short part;
-
- SetPort(theWindow);
- mouse = theEvent.where; /*Get the mouse location*/
- GlobalToLocal(&mouse); /*convert to local coordinates*/
- part = FindControl(mouse, theWindow, &control);
-
- if(part == inCheckBox)
- DoCheckBox(mouse, control);
-
- }
-
- void DoCheckBox(Point mouse, ControlHandle control)
- {
- short checkbox;
- Handle theSound;
-
- if (TrackControl(control, mouse, nil)) /*user clicks checkbox*/
- {
- checkbox = GetCtlValue(control); /*get last value of checkbox*/
- checkbox = 1- checkbox; /*toggle value of checkbox*/
- SetCtlValue(control, checkbox); /*set checkbox to new value*/
- if(checkbox == 1) /*express yourself next time user clicks the checkbox*/
- {
- theSound = GetResource('snd ', kSoundID);
- if (theSound != nil) {
- SndPlay(nil, theSound, false);
- ReleaseResource(theSound);
- }
- }
- }
- }
-